package com.example.administrator.yuejian23.Activity;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.administrator.yuejian23.Bean.MyShaitu;
import com.example.administrator.yuejian23.Const;
import com.example.administrator.yuejian23.R;
import com.example.administrator.yuejian23.Retrofit.RetrofitService;
import com.example.administrator.yuejian23.adapter.UserShaituAdapter;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Administrator on 2017/10/18.
 */

public class MyShaiTuActivity extends Activity {
    private RecyclerView recyclerView;
    private Retrofit retrofit;
    private UserShaituAdapter userShaituAdapter;
    private List<MyShaitu> userShaituList;
    private String User_Name;
    private String User_Id;
    private String User_Pic;
    private int user_id;
    private TextView user_name;
    private ImageView user_pic;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_shaitu);
        user_id = getApplication().getSharedPreferences("userInfo", Context.MODE_PRIVATE)
                .getInt("user_id",0);
      /*  User_Id=getIntent().getStringExtra("User_Id");*/
        User_Name=getIntent().getStringExtra("User_Name");
        User_Pic=getIntent().getStringExtra("User_Pic");
        recyclerView= (RecyclerView) findViewById(R.id.user_shaitu_recyclerview);
        retrofit=new Retrofit.Builder()
                .baseUrl(Const.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        RetrofitService service=retrofit.create(RetrofitService.class);
        retrofit2.Call<List<MyShaitu>> call=service.getUserShaitu(user_id);
        call.enqueue(new Callback<List<MyShaitu>>() {
            @Override
            public void onResponse(Call<List<MyShaitu>> call, Response<List<MyShaitu>> response) {
                List<MyShaitu> list=response.body();
                userShaituAdapter=new UserShaituAdapter(MyShaiTuActivity.this,list,User_Name,User_Pic);
                LinearLayoutManager linearLayoutManager = new LinearLayoutManager(MyShaiTuActivity.this);
                linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                recyclerView.setLayoutManager(linearLayoutManager);
                recyclerView.setAdapter(userShaituAdapter);
                recyclerView.setItemAnimator(new DefaultItemAnimator());
            }

            @Override
            public void onFailure(Call<List<MyShaitu>> call, Throwable t) {
                Toast.makeText(MyShaiTuActivity.this,"获取列表失败",Toast.LENGTH_SHORT).show();
            }
        });
    }
}
